package top.lyc829.leetcode.T155;

import java.util.ArrayList;

class MinStack {

    ArrayList<Integer> list = null;

    /**
     * initialize your data structure here.
     */
    public MinStack() {
        this.list = new ArrayList<>();
    }

    public void push(int x) {
        list.add(x);
    }

    public void pop() {
        if (!list.isEmpty()) {
            list.remove(list.size() - 1);
        }

    }

    public int top() {
        if (!list.isEmpty()) {
            return list.get(list.size() - 1);
        }
        return 0;
    }

    public int getMin() {
        int min = Integer.MAX_VALUE;
        for (int num : list) {
            if (num < min) {
                min = num;
            }
        }
        return min;
    }
}